﻿// Learn more about F# at http://fsharp.net

namespace ArtificalInteligence

open System
open SerialozLibrary
open System.Drawing
open System.Text

type public NeuronNetworkGenerator =class

     val typeEss:Type
     val sizeEss:Size
     val startPoint:Point

     public new (t:Type, size:Size, stP:Point) = {
        typeEss=t
        sizeEss=size
        startPoint=stP
     }

     member m.generateNeuronNetwork(countLayer:int, countNeuron:array<int>, idFunction:int, paramsFunc:array<System.Object>)=
        let stPo=ref m.startPoint
        let idNeuron=ref 0
        let sumNeuron = Array.init (countLayer) (fun j ->  stPo:=new Point((!stPo).X+40, (!stPo).Y)
                                                           let b=Array.init (Convert.ToInt32(countNeuron.GetValue(j))) 
                                                                            (fun i -> let mutable a = new DummyGhost()
                                                                                      a.dummyID<-(!idNeuron)
                                                                                      idNeuron:=(!idNeuron)+1
                                                                                      a.dummyType<-m.typeEss
                                                                                      a.noneScaleSize<-m.sizeEss
                                                                                      a.noneScaleLocation<-(!stPo)
                                                                                      a.data<-paramsFunc
                                                                                      stPo:=new Point((!stPo).X,(!stPo).Y+25)
                                                                                     
                                                                                      a
                                                                             )
                                                           b              
                                                        ) |> Array.collect (fun t -> t) 
        sumNeuron
        
     member m.generateLinks(countNeuron:array<int>, countLayer:int) =
        let idNeuron=ref 0
        
        Array.init (countLayer-1) 
                   (fun i -> 
                      let index=Convert.ToInt32(countNeuron.GetValue(i))
                      let a=Array.init(index) 
                                      (fun j ->  
                                           Array.init (Convert.ToInt32(countNeuron.GetValue(i+1))) 
                                                      (fun x -> 
                                                           let mutable link=new LinkGhost()
                                                           link.slot1_name<-new  StringBuilder("slot2")
                                                           link.slot2_name<-new  StringBuilder("slot1")
                                                           link.dummy1_id<-(!idNeuron)+j
                                                           link.dummy2_id<-(!idNeuron)+Convert.ToInt32(countNeuron.GetValue(i))+x
                                                           link.value<-0.0
                                                           link
                                                      )
                                      )
                      idNeuron:=(!idNeuron)+index
                      a
                   )|> Array.collect (fun t -> t) |> Array.collect (fun t -> t)
     
     member public m.generateStream(countLayer:int, countNeuron:array<int>, functionActiv:int, parameters:array<Object>) =
         let mutable ss:ser_tmp_=new ser_tmp_()
         ss.dummies<-m.generateNeuronNetwork(countLayer, countNeuron, functionActiv,parameters)
         ss.links<-m.generateLinks(countNeuron, countLayer)
         ss

end
